package com.jiyun;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;
import java.util.Map;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext-redis.xml")
public class SpringdataRedisDemo_Hash {

    @Autowired
    RedisTemplate redisTemplate;

    /*
    List类型增删改查  key—[v,v,v,v,v,v,v]
     */

    @Test
    public void add(){
      // redisTemplate.boundHashOps("user").put("name","张三");
      // redisTemplate.boundHashOps("user").put("age",20);
      // redisTemplate.boundHashOps("user").put("sex","男");
         redisTemplate.boundHashOps("user").put("name","李四");
    }

    @Test
    public void query(){
        System.out.println(redisTemplate.boundHashOps("user").get("sex"));
        Map user = redisTemplate.boundHashOps("user").entries();
        for (Object o : user.keySet()) {
            System.out.println(o+"--"+user.get(o));
        }
    }

    @Test
    public void delItem(){
        redisTemplate.boundHashOps("user").delete("name","age");
    }

}
